Draft
Conversation
| /// - Note can be partially or fully filled by consumers | ||
| /// - Unfilled portions create remainder notes | ||
| /// - Creator receives requested assets via P2ID notes | ||
| pub struct PswapNote; |
Contributor
There was a problem hiding this comment.
Since we're adding this as a completely new note, it would be great if we could immediately set it up with the structure we want to end up with, i.e. the one described in #2283.
So roughly:
pub struct PswapNoteStorage {
requested_key: Word,
requested_value: Word,
swapp_tag: NoteTag,
p2id_tag: NoteTag,
swap_count: u64,
creator_account_id: AccountId,
}
impl PswapNoteStorage {
pub fn into_recipient(self, serial_num: Word) -> NoteRecipient {
todo!()
}
}
impl From<PswapNoteStorage> for NoteStorage {
fn from(pswap_storage: PswapNoteStorage) -> Self {
todo!()
}
}
#[derive(Debug, Clone, bon::Builder)]
#[builder(finish_fn(vis = "", name = build_internal))]
pub struct PswapNote {
sender: AccountId,
storage: PswapNoteStorage,
serial_number: Word,
#[builder(default = NoteType::Private)]
note_type: NoteType,
#[builder(default)]
assets: NoteAssets,
#[builder(default)]
attachment: NoteAttachment,
}
impl PswapNote {
pub fn execute(
&self,
consumer_account_id: AccountId,
input_amount: u64,
inflight_amount: u64,
) -> Result<(Note, Option<PswapNote>), NoteError> {
todo!("what create_output_notes does now")
}
}This would result in a more natural API, i.e. execute takes &self instead of create_output_notes taking an arbitrary &Note.
What do you think?
Author
There was a problem hiding this comment.
Yes, agree to this.
I have made the change.
added 5 commits
March 20, 2026 09:06
…MS, remove create_ wrappers, add builder finish_fn - Rename swapp_tag -> pswap_tag and SWAPp -> PSWAP throughout - Rename NUM_ITEMS -> NUM_STORAGE_ITEMS for clarity - Remove create_p2id_payback_note and create_remainder_note wrappers, make build_ functions public instead - Compute p2id_tag inside build_p2id_payback_note from self.storage - Add #[builder(finish_fn(vis = "", name = build_internal))] to PswapNote
…ctly Replace all test helper wrappers with direct calls to library functions: - create_pswap_note -> PswapNote::create() - create_expected_pswap_p2id_note + create_expected_pswap_remainder_note -> pswap.execute() - build_pswap_storage -> PswapNoteStorage::from_parts() - Remove make_pswap_tag, make_note_assets, make_note_args, compute_p2id_tag_* - Inline calculate_output_amount as PswapNote::calculate_output_amount()
- Replace storage layout list with markdown table - Remove trivial "Returns the X" docs on simple getters - Add # Errors sections where relevant - Rewrite method docs to describe intent, not implementation - Add one-line docs on From/TryFrom conversion impls - Tighten PswapNote struct doc
c04d47c to
0f1b15b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add PSWAP (partially-fillable swap) note to miden-standards — a new note script that enables partial
fills, creator reclaim, and inflight cross-swaps for decentralized asset exchange
1e5 precision factor, and an early-return optimization for full fills to avoid integer truncation
remainder), storage parsing, and calculate_offered_for_requested convenience method
reclaim, invalid input rejection, multiple fill amounts, non-exact ratios, fuzz cases, and chained
partial fills
Test plan
calculation, storage parsing)
reclaim, fuzz, chained fills)